package runInfo;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DecimalFormat;

/**
 * Created by IntelliJ IDEA.
 * User: Mike
 * Date: 10/29/11
 * Time: 6:15 PM
 * To change this template use File | Settings | File Templates.
 */
public class Writer {

    static void WriteData(Double runningTime) throws IOException {        //Write out Files ================================================================
        if (TestThreadGUI.isWriteOut()) {
            String Dir = "C:\\WhiskeyData\\output.txt";
            DecimalFormat df1 = new DecimalFormat("###.##");

            FileWriter write = new FileWriter(Dir, true);
            PrintWriter text = new PrintWriter(write, true);

            if (TestThreadGUI.isHeaderFlag() == true) {

                String output = "datetime"
                        + "\t" + "milliTime"
                        + "\t" + "min"
                        + "\t" + "columnC"
                        + "\t" + "columnF"
                        + "\t" + "ambientC"
                        + "\t" + "ambientF"
                        + "\t" + "bottleNumber"
                        + "\t" + "correctedAbv"
                        + "\t" + "uncorrectedAbv"
                        + "\t" + "distillateTempC"
                        + "\t" + "boilerTempC"
                        + "\t" + "spaceHere";
                System.out.println(output);
                text.println(output);
                text.flush();
                write.close();
                text.close();
                write = null;
                text = null;
                TestThreadGUI.setHeaderFlag(false);
            } else {
                String output = TestThreadGUI.CurrentTime()
                        + "\t" + Data.milliTime
                        + "\t" + df1.format(runningTime)
                        + "\t" + Data.tempTC
                        + "\t" + Data.tempTF
                        + "\t" + Data.tempAC
                        + "\t" + Data.tempAF
                        + "\t" + Data.bottleS
                        + "\t" + Data.corrAbvS
                        + "\t" + Data.measAbvS
                        + "\t" + Data.distTemp
                        + "\t" + Data.boilTempS;
                System.out.println(output);
                text.println(output);
                text.flush();
                write.close();
                text.close();
                write = null;
                text = null;
                Data.numOfWrites++;
            }
        }
    }

}
